/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProgramAboutBox.java
 *
 * Created on May 19, 2010, 11:52:06 PM
 */

package MainProgram.UI;

import Global.Constants;
import Global.ProgramSettings;
import MainProgram.ProgramLaunchers.ProgramLauncher;
import Resources.ResourceAddingWindow;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import org.jdesktop.application.Action;
import org.jdesktop.application.Task;

/**
 *
 * @author Stephen
 */
public class ProgramAboutBox extends javax.swing.JDialog
{
    /** Creates new form ProgramAboutBox */
    public ProgramAboutBox()
    {
        initComponents();
        setModalityType(ModalityType.APPLICATION_MODAL);
        setIconImage(ProgramLauncher.getProgramIcon(this));        
        v_instructionsTextBox.append("Map Creator Version:                   " + Constants.ProgramVersion.toString() + "\r\n\r\nStability:                                       " + (Constants.IsProgramStable ? "Stable" : "Not Stable") + "\r\n\r\nTripleA Available At Release:       " + Constants.TripleAVersionAvailableAtRelease.toString());
    }
    public Task getScrollTask()
    {
        return new ScrollTask(org.jdesktop.application.Application.getInstance());
    }
    private class ScrollTask extends org.jdesktop.application.Task<Object, Void> {
        ScrollTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to AsdfsafTask fields, here.
            super(app);
        }
        @Override
        protected Object doInBackground()
        {
            return null;
        }
        @Override protected void succeeded(Object result)
        {
            v_instructionsScrollPane.getViewport().setViewPosition(new Point(0,0));
            v_closeButton.grabFocus();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        v_instructionsScrollPane = new javax.swing.JScrollPane();
        v_instructionsTextBox = new javax.swing.JTextArea();
        v_creditsButton = new javax.swing.JButton();
        v_venryxDevelopments = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        v_closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(ProgramAboutBox.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                WindowShown(evt);
            }
        });

        v_instructionsScrollPane.setBorder(null);
        v_instructionsScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        v_instructionsScrollPane.setName("v_instructionsScrollPane"); // NOI18N

        v_instructionsTextBox.setBackground(resourceMap.getColor("v_instructionsTextBox.background")); // NOI18N
        v_instructionsTextBox.setColumns(20);
        v_instructionsTextBox.setEditable(false);
        v_instructionsTextBox.setFont(resourceMap.getFont("v_instructionsTextBox.font")); // NOI18N
        v_instructionsTextBox.setLineWrap(true);
        v_instructionsTextBox.setRows(4);
        v_instructionsTextBox.setText(resourceMap.getString("v_instructionsTextBox.text")); // NOI18N
        v_instructionsTextBox.setWrapStyleWord(true);
        v_instructionsTextBox.setBorder(null);
        v_instructionsTextBox.setDisabledTextColor(resourceMap.getColor("v_instructionsTextBox.disabledTextColor")); // NOI18N
        v_instructionsTextBox.setFocusable(false);
        v_instructionsTextBox.setName("v_instructionsTextBox"); // NOI18N
        v_instructionsScrollPane.setViewportView(v_instructionsTextBox);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(ProgramAboutBox.class, this);
        v_creditsButton.setAction(actionMap.get("ShowCredits")); // NOI18N
        v_creditsButton.setText(resourceMap.getString("v_creditsButton.text")); // NOI18N
        v_creditsButton.setName("v_creditsButton"); // NOI18N

        v_venryxDevelopments.setText(resourceMap.getString("v_venryxDevelopments.text")); // NOI18N
        v_venryxDevelopments.setName("v_venryxDevelopments"); // NOI18N
        v_venryxDevelopments.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                v_venryxDevelopmentsActionPerformed(evt);
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.GridBagLayout());

        v_closeButton.setAction(actionMap.get("CloseWindow")); // NOI18N
        v_closeButton.setText(resourceMap.getString("v_closeButton.text")); // NOI18N
        v_closeButton.setName("v_closeButton"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.ipadx = 65;
        gridBagConstraints.ipady = 10;
        jPanel1.add(v_closeButton, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(v_instructionsScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(v_venryxDevelopments)
                        .addGap(7, 7, 7)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE)
                        .addGap(5, 5, 5)
                        .addComponent(v_creditsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(v_instructionsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(v_venryxDevelopments, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(v_creditsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-703)/2, (screenSize.height-449)/2, 703, 449);
    }// </editor-fold>//GEN-END:initComponents

    private void WindowShown(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_WindowShown
    {//GEN-HEADEREND:event_WindowShown
        getScrollTask().execute();
    }//GEN-LAST:event_WindowShown

    private void v_venryxDevelopmentsActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_v_venryxDevelopmentsActionPerformed
    {//GEN-HEADEREND:event_v_venryxDevelopmentsActionPerformed
        final JDialog splashWindow = new JDialog(this);
        splashWindow.setIconImage(ProgramLauncher.getProgramIcon(splashWindow));
        splashWindow.setUndecorated(true);
        splashWindow.setLayout(new GridLayout());
        splashWindow.addMouseListener(new MouseAdapter()
        {
            @Override
            public void mouseReleased(MouseEvent e)
            {
                splashWindow.dispose();
            }
        });
        
        Dimension screenSize = getToolkit().getScreenSize();

        Image loaded = ResourceAddingWindow.GetImage("2.png");
        
        float cWidthToIWidth = (float) screenSize.width / (float) loaded.getWidth(this);
        float cHeightToIHeight = (float) screenSize.height / (float) loaded.getHeight(this);

        float multiplyAmount = Math.min(cWidthToIWidth, cHeightToIHeight);

        int newWidth = (int) (loaded.getWidth(this) * multiplyAmount);
        int newHeight = (int) (loaded.getHeight(this) * multiplyAmount);

        Image image = loaded.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);

        ImageIcon imageIcon = new ImageIcon(image);
        JLabel splashLabel = new JLabel(imageIcon)
        {
            @Override
            public void paint(Graphics g)
            {
                g.setColor(Color.black);
                g.fillRect(0, 0, this.getWidth(), this.getHeight());
                super.paint(g);
            }
        };
        splashWindow.add(splashLabel);
        
        splashWindow.setSize(screenSize.width, screenSize.height);
        splashWindow.setLocation(0, 0);        
        splashWindow.setVisible(true);
    }//GEN-LAST:event_v_venryxDevelopmentsActionPerformed

    @Action
    public void CloseWindow()
    {
        this.dispose();
    }

    @Action
    public void ShowCredits()
    {
        ProgramCreditsWindow window = new ProgramCreditsWindow(this);
        window.setLocationRelativeTo(this);
        window.setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton v_closeButton;
    private javax.swing.JButton v_creditsButton;
    private javax.swing.JScrollPane v_instructionsScrollPane;
    private javax.swing.JTextArea v_instructionsTextBox;
    private javax.swing.JButton v_venryxDevelopments;
    // End of variables declaration//GEN-END:variables

}
